{% extends "V.html" %}

{% block head %}

<script type="text/javascript" src="/static/matrix/js/layer/layer.js"></script>
<script type="text/javascript" src="/static/matrix/js/dataBase.js"></script>
<script type="text/javascript" src="/static/matrix/js/preview/WdatePicker.js"></script>
<script type="text/javascript" src="/static/matrix/js/download.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		{% if perms.Matrix.platforminfo_pagedataList %}
			loadTable(1);
		{% else %}
	    $('#dataFrom').html('对不起,您没有查看权限,请联系系统管理员').css('text-align','center');
	    {% endif%}
	});

	function addDialog(){
		var addTableHtml=$("#addTable").clone();
		var parameters=['id','name','domain','url','phonecall','memo'];

		// var inputStatus=addTableHtml.find("select[name='status']");
		// 	inputStatus.attr("id","status");
		// 	if(arguments[4]){
		// 		inputStatus.find("option[name='"+arguments[4]+"']").attr("selected",true);
		// 	}

    if(arguments[0]){
      var buttonValue="更新";
      $.each(arguments,function(num,val){
        var inputName=addTableHtml.find("input[name='"+parameters[num]+"']");
        if(parameters[num]=='name'){
          inputName.attr("readonly","readonly");
        }
          inputName.attr("id",parameters[num]);
          inputName.attr("value",val);
      });
    }else{
      var buttonValue="添加";
      $.each(parameters,function(){
        var inputName=addTableHtml.find("input[name='"+this+"']");
          inputName.attr("id",this);
      });
    }

		layer.open({
					title:'编辑信息',
				 	type: 1,
					shift:2,
					skin: 'layui-layer-rim', //加上边框
					area: ['30%', '41%'], //宽高
					content:addTableHtml.html(),
					btn:[buttonValue,'取消'],
					yes:function(index){

						var ret='';
						$.each(parameters,function(){
							ret+=this+'='+$("#"+this).val()+'&';
						});
						ret+="hostop={{ true_name }}"
						// 测试输出
						console.log(ret)
						$.ajax({
							type:'POST',
							url:'/base_data/platforminfo_editFun',
							data:ret,
							dataType:'text',
							success:function(val){
								layer.close(index);
								if(val=='1'){
									loadTable(1);
								}else{
									layer.alert("操作失败");
								}
							},error:function(){
								layer.close(index);
								laery.alert("操作失败");
							}
						});

					}
			});
	}

	function keyEnter(event){
		 var e = event || window.event || arguments.callee.caller.arguments[0];
		 if(e && e.keyCode==13){ // enter 键
             loadTable(1);
			return false;
          }

	}

	function loadTable(val){
		 $("#dataFrom").find("input[name='page']").val(val);
		 $("#dataTab").dataTable({
				title:'云平台配置信息详情',
				columns:[
				{key:'id',check:true,checkAll:true,width:'1%',align:'center'},
				// {key:'id',name:'数据库ID',width:'5%',align:'center'},
				{key:'name',name:'云平台服务商',width:'20%',align:'center'},
				{key:'domain',name:'云平台域名',width:'10%',align:'center'},
				{key:'url',name:'云平台URL',width:'5%',align:'center'},
				{key:'phonecall',name:'联系电话',width:'20%',align:'center'},
				{key:'memo',name:'备注信息',width:'20%',align:'center'}],
				formid:'dataFrom',
				loadAfter:tab_trOnclick,
		});
	}

	/**
	行添加双击事件
	**/
	{% if perms.Matrix.platforminfo_editFun %}
	function tab_trOnclick(){
		var trs=$("#dataFrom_table tbody tr");
		for(var i=0;i<trs.length;i++){
			$(trs[i]).on("dblclick",function(){
				var tr=$(this);
				var tds=tr.find("td");
				var cloudurl=tr.find("a");
				var id=$(tds[0]).find("input").val();
				addDialog(id,$(tds[1]).text(),$(tds[2]).text(),$(tds[3]).text(),$(tds[4]).text(),$(tds[5]).text());
			});
		}
	}
	{% else %}
	  function tab_trOnclick(){
	    
	  }

	{% endif%}
	/**
	删除功能
	**/
	function delData(){
		var inputChecks=$("input:checkbox[name='dataFrom_check']:checked");
		if(inputChecks.length==0){
			layer.alert('请选中删除项！');
			return;
		}
		layer.confirm('关联此平台的所有云资源会被删除，确认删除?', {icon: 2, title:'提示'},function(index){
			var orders='';
			for(var i=0;i<inputChecks.length;i++){
				orders+=inputChecks[i].value;
				if(i!=inputChecks.length-1){
					orders+=',';
				}
			}
			$.ajax({
				type:'POST',
				url:'/base_data/platforminfo_deleteFun',
				dataType:'text',
				data:'id='+orders,
				success:function(text){
				       layer.close(index);
				       if(text=='1'){
				       	loadTable(1);
				       }else{
				       	layer.alert('操作失败');
				       }
				},error:function(){
					layer.close(index);
					layer.alert('操作失败');
				}
			});
		});

	}
</script>
{% endblock %}

{% block content %}
<!-- 承上连接V.html：content+content-header -->

  <div class="container-fluid">
    <div class="row-fluid">
      <div class="span12">
   <!--aaa-->
    <form action="/base_data/platforminfo_pagedataList" id="dataFrom" onSubmit="return false">
    	<input type="hidden" id="page" name="page" value="1"/>
        <input type="hidden" id="num" name="num" value="15"/>
        <div>
        	{% if perms.Matrix.platforminfo_pagedataList %}
        		<input type="text" name="tj" placeholder="请输入关键字,回车查询" id="tj" style="background-color: white; float:right" onKeydown="keyEnter();"/>
        	{% endif %}
        	{% if perms.Matrix.platforminfo_editFun %}
				<input class="btn btn-primary" type="button" name="addButton" value="添加" onclick="addDialog();" style="float:left;"/>
			{% endif %}
			{% if perms.Matrix.platforminfo_deleteFun %}
				<input class="btn btn-danger" type="button" name="deleteButton" value="删除" onclick="delData();" style="float:left;"/>
			{% endif %}
		</div>
    </form>
    <input id="downData" class="btn btn-info" type="button" value="导出" name="Platform" onclick="downData();">
	<div id="dataTab"></div>
    <!-- end aa-->

  <div id="addTable" style="display:none;">
  		<center>
        	 <table border="0" style="color:#000;">
        	    <tr style="display:none;">
                	<td style="text-align:right;"><span style="position:relative; top:-5px;"></span></td>
                    <td><input type="text" name="id"/></td>
                </tr>
                <tr>
                	<td style="text-align:right;"><span style="position:relative; top:-5px;">云平台服务商：</span></td>
                    <td><input type="text" name="name"/></td>
                </tr>
                <tr>
                	<td style="text-align:right;"><span style="position:relative; top:-5px;">云平台域名：</span></td>
                    <td><input type="url" name="domain"/></td>
                </tr>
                <tr>
                	<td style="text-align:right;"><span style="position:relative; top:-5px;">云平台URL：</span></td>
                    <td><input type="url" name="url"/></td>
                </tr>
                <tr>
                	<td style="text-align:right;"><span style="position:relative; top:-5px;">云平台联系方式：</span></td>
                    <td><input type="text" name="phonecall"/></td>
                </tr>
                <tr>
                	<td style="text-align:right;"><span style="position:relative; top:-5px;">备注信息：</span></td>
                    <td><input type="text" name="memo"/></td>
                </tr>
                <tr>
                  <td style="text-align:right;"><span style="position:relative; top:-5px;">最后更新操作人员：</span></td>
                    <td><input type="text" name="dnsop" placeholder={{true_name}} value={{true_name}} /></td>
                </tr>
            </table>
         </center>
   </div>

   </div>
   </div>
   </div>

{% endblock %}